package com.xdq.quartz;

import org.quartz.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author: 徐东强
 * @date: 2018/9/28 下午7:20
 * @description:
 **/
@RestController
@RequestMapping("/job")
public class JobController {

    private final SchedulerService schedulerService;

    @Autowired
    public JobController(SchedulerService schedulerService) {
        this.schedulerService = schedulerService;
    }

    @GetMapping("/execute")
    public void execute() throws SchedulerException {
        this.schedulerService.executeJobAtNow();
    }

    @GetMapping("/clear")
    public void clear() throws SchedulerException {
        this.schedulerService.clearAll();
    }

    @GetMapping("/pause")
    public void pauseJob() throws SchedulerException {
        this.schedulerService.pauseJob();
    }

    @GetMapping("/resume")
    public void resume() throws SchedulerException {
        this.schedulerService.resumeJob();
    }

    @GetMapping("/update")
    public void update() throws SchedulerException {
        this.schedulerService.update();
    }

    @GetMapping("/updateTrigger")
    public void updateTrigger() throws SchedulerException {
        this.schedulerService.updateTrigger();
    }

    @GetMapping("/get")
    public JobDetail getOneJob() throws SchedulerException {
        return this.schedulerService.getOneJob();
    }

    @GetMapping("/getTrigger")
    public Trigger getOneTrigger() throws SchedulerException {
        return this.schedulerService.getOneTrigger();
    }

    @GetMapping("/listTriggers")
    public List<Trigger> listTriggers() throws SchedulerException {
        return this.schedulerService.listTriggers();
    }

    @GetMapping("/add")
    public void addJob(String i) throws SchedulerException {
        this.schedulerService.addJob(i);
    }

}
